package exer;

/**
 * @author shkstart
 * @create 2022-08-15-15:32
 */
public class mianshi0204 {
    public ListNode partition(ListNode head, int x) {

        ListNode smallHead = new ListNode(-1);
        ListNode bigHead = new ListNode(-1);
        ListNode smallTail = smallHead;
        ListNode bigTail = bigHead;
        while (head != null) {
            if (head.val < x) {
                smallTail.next = head;
                smallTail = smallTail.next;
            }else {
                bigTail.next = head;
                bigTail=bigTail.next;
            }
            head = head.next;
        }
        smallTail.next=null;
        bigTail.next=null;
        smallTail.next = bigHead.next;
        return  smallHead.next;
    }
}
